package com.install.rabbitmq.service.impl;

import com.install.rabbitmq.service.RabbitMqService;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class RabbitMqServiceImpl implements RabbitMqService {

    private static Logger logger = LoggerFactory.getLogger(RabbitMqServiceImpl.class);

    @Resource(name = "rabbitTemplate")
    private RabbitTemplate rabbitTemplate;


    @Value("${mq.exchange}")
    private String exchange;

    @Value("${mq.routekey}")
    private String routeKey;


    @Override
    public void sendMessage(String message) {
        try {
            rabbitTemplate.convertAndSend(exchange, routeKey, message);
        } catch (Exception e) {
            logger.error("RabbitMqServiceImpl->Exception", ExceptionUtils.getMessage(e));
        }

    }
}
